/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rg1guidemo;

import java.awt.CardLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author apple
 */
public class CardFrame extends JFrame implements ActionListener
{
    private JPanel leftPanel;
    private JPanel rightPanel;
    
    private CardLayout cardLayout;
    private JButton nextButton;
    private JButton previousButton;

    public CardFrame() {
        this.setBounds(400, 300, 600, 400);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
        leftPanel =new JPanel();
        rightPanel=new JPanel();
        this.add(leftPanel);
        this.add(rightPanel);
        this.setLayout(new GridLayout(1, 2));
        cardLayout=new CardLayout(10, 10);
        leftPanel.setLayout(cardLayout);
        for(int i=0;i<50;i++)
        {
            JButton button=new JButton("Button"+i);
            leftPanel.add(button);
        }
        
        rightPanel.setLayout(new GridLayout(2, 1, 40, 40));
        nextButton=new JButton("NEXT");
        nextButton.addActionListener(this);
        previousButton=new JButton("PRERIOUS");
        previousButton.addActionListener(this);
        rightPanel.add(nextButton);
        rightPanel.add(previousButton);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource().equals(nextButton))
        {
            cardLayout.next(leftPanel);
        }
        if(e.getSource().equals(previousButton))
        {
            cardLayout.previous(leftPanel);
        }
    }
    
    
    
    
}
